package com.sls.nzdapplication.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

import android.content.Intent;
import android.content.res.Configuration;
import android.media.ExifInterface;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.hmy.popwindow.PopItemAction;
import com.hmy.popwindow.PopWindow;
import com.sls.nzdapplication.R;
import com.sls.nzdapplication.app.MySharedPreferences;
import com.sls.nzdapplication.util.DestroyActivityUtil;

import java.io.IOException;
import java.util.List;

import me.jessyan.autosize.internal.CustomAdapt;
import top.littlefogcat.danmakulib.danmaku.CachedDanmakuViewPool;
import top.littlefogcat.danmakulib.danmaku.Danmaku;
import top.littlefogcat.danmakulib.danmaku.DanmakuManager;
import top.littlefogcat.danmakulib.danmaku.DanmakuView;
import top.littlefogcat.danmakulib.danmaku.DanmakuViewPool;
import top.littlefogcat.danmakulib.danmaku.Pool;

public class MyActivity extends AppCompatActivity implements View.OnClickListener , CustomAdapt {

    private CardView zyCardView,dyCardView;

    private TextView logout,layerbar;

    private MySharedPreferences mySharedPreferences;

    private int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_layout);
        zyCardView = findViewById(R.id.zy_map_layer);
        zyCardView.setOnClickListener(this);
        dyCardView = findViewById(R.id.dy_map_layer);
        dyCardView.setOnClickListener(this);
        logout = findViewById(R.id.logout);
        logout.setOnClickListener(this);
        layerbar = findViewById(R.id.layer_bar);
        layerbar.setOnClickListener(this);
        mySharedPreferences = new MySharedPreferences(getApplicationContext());

    }

    //这是你们首席测试MLQ说要加的
    private void danmu(){
        DanmakuManager dm = DanmakuManager.getInstance();
        FrameLayout container = findViewById(R.id.container_mlq);
        dm.setDanmakuContainer(container);
        dm.init(getApplicationContext(),container);

        Danmaku danmaku = new Danmaku();
        danmaku.text = "我们走得太快，是该停下来等等自己的灵魂了！";
        danmaku.color = "#00574B";
        danmaku.size = 35;
        dm.send(danmaku);
    }



    private void logoutUser(){
        new PopWindow.Builder(this)
                .setStyle(PopWindow.PopWindowStyle.PopUp)
                .setTitle("注销当前用户！")
                .addItemAction(new PopItemAction("确定", PopItemAction.PopItemStyle.Warning, new PopItemAction.OnClickListener() {
                    @Override
                    public void onClick() {
                        mySharedPreferences.clearUserInfo();
                        mySharedPreferences.clearActiveTaskId();
                        mySharedPreferences.clearOpenTaskId();
                        Intent intent = new Intent(MyActivity.this,LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);		//将DengLuActivity至于栈顶
                        startActivity(intent);
                        DestroyActivityUtil.exit();
                        MyActivity.this.finish();
                    }
                }))
                .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Cancel))
                .show();

    }

    @Override
    public void onClick(View view) {
        if(view == zyCardView){
            startActivity(new Intent(MyActivity.this,ZyWorkActivity.class));
        }
        if(view == dyCardView){
            startActivity(new Intent(MyActivity.this,DyWorkActivity.class));
        }
        if(view == logout){
            logoutUser();
        }
        if(view == layerbar){
            i++;
            if(i==10){
                danmu();
                i=0;
            }
        }

    }

    @Override
    public boolean isBaseOnWidth() {
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
            return true;//根据宽度适配
        } else {
            return false;//根据高度适配
        }
    }

    @Override
    public float getSizeInDp() {
        // 横屏下的高度不就是竖屏的宽度吗,所以统一返回宽度即可
        return 500;
    }
}